/*
 * @Author: yangni 920556271@qq.com
 * @Date: 2023-12-25 17:42:54
 * @LastEditors: YangJianFei
 * @LastEditTime: 2024-08-23 10:58:10
 * @FilePath: /yt_devop_app/lib/services/auth/auth_services.dart
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */

import 'package:native_dart_package/http/request/exception/api_exception.dart';
import 'package:yt_devops/configs.dart';

import '../predicates.dart';

class AuthServices {
  Future login(params, {onError}) {
    return Configs.httpClient
        .post('$preApi/app/login', data: params, onError: onError);
  }

  Future getUserInfo() {
    return Configs.httpClient.get('$system/appUser');
  }

  /// 退出登录
  Future logout(params, {onError}) {
    return Configs.httpClient.post(
      '$preApi/app/logout',
      data: params,
      onError: onError,
    );
  }

  /// 获取用户tag
  Future pushTags({bool Function(ApiException)? onError}) {
    return Configs.httpClient.get('$preApi/app/push/tag', onError: onError);
  }

  ///获取用户管理列表
  Future getUserManagerList(param, {bool Function(ApiException)? onError}) {
    return Configs.httpClient
        .get('$uc/user/page', queryParameters: param, onError: onError);
  }

  ///获取用户组织树
  Future getUserManagerSiteTree(param, {bool Function(ApiException)? onError}) {
    // return Configs.httpClient.get('$uc/user/app/orgSiteTree',
    //     queryParameters: param, onError: onError);
    return Configs.httpClient
        .get('$uc/user/orgSiteTree', queryParameters: param, onError: onError);
  }

  ///系统管理员获取用户组织树
  Future getAdminSiteTree(param, {bool Function(ApiException)? onError}) {
    // return Configs.httpClient.get('$uc/user/app/orgSiteTree',
    //     queryParameters: param, onError: onError);
    return Configs.httpClient
        .get('$uc/site/threeLevelSiteTree', queryParameters: param, onError: onError);
  }

  ///新增用户
  Future userManagerAddUser(param, {bool Function(ApiException)? onError}) {
    return Configs.httpClient.post('$uc/user', data: param, onError: onError);
  }

  ///获取用户详情
  Future getUserManagerDetail(param, {bool Function(ApiException)? onError}) {
    return Configs.httpClient
        .get('$uc/user', queryParameters: param, onError: onError);
  }

  ///编辑
  Future eEditUserManagerDetail(param, {bool Function(ApiException)? onError}) {
    return Configs.httpClient.put('$uc/user', data: param, onError: onError);
  }

  ///获取用户站点列表
  Future getUserManagerSiteList(param, {bool Function(ApiException)? onError}) {
    return Configs.httpClient
        .get('$uc/user/site/page', queryParameters: param, onError: onError);
  }

  ///修改用户状态
  Future changeUserStatus(param, {bool Function(ApiException)? onError}) {
    return Configs.httpClient
        .put('$uc/user/changeStatus', data: param, onError: onError);
  }

  ///修改用户密码
  Future resetUserPwd(param, {bool Function(ApiException)? onError}) {
    return Configs.httpClient
        .put('$uc/user/resetPwd', data: param, onError: onError);
  }

  ///产品管理员账户选择组织列表
  Future productOrganizationList(param,
      {bool Function(ApiException)? onError}) {
    return Configs.httpClient
        .get('$uc/user/org/list', queryParameters: param, onError: onError);
  }

  ///获取当前用户能创建的角色的组织哪些是存在的 0-业主 1-安装商
  Future getExistOrganization({bool Function(ApiException)? onError}) {
    return Configs.httpClient.get('$uc/org/getExistOrg', onError: onError);
  }

  ///获取当前当前用户角色列表
  Future getRoleList(param, {bool Function(ApiException)? onError}) {
    return Configs.httpClient
        .get('$uc/user/role/list', queryParameters: param, onError: onError);
  }

  Future updatePwd(param) {
    return Configs.httpClient
        .put('$system/user/profile/updatePwd', queryParameters: param);
  }

  Future updateStatusByUserId(param) {
    return Configs.httpClient.put('$uc/user/updateStatusByUserId', data: param);
  }

  ///更新用户信息
  Future updateUserInfo(param, {bool Function(ApiException)? onError}) {
    return Configs.httpClient
        .put('$system/user/profile', data: param, onError: onError);
  }
}
